package com.yuyou.fn.tms.controller;

import com.yuyou.fn.tms.service.IQueryDataService;
import com.yuyou.fn.tms.util.Signs;
import com.yuyou.fn.tms.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Controller
@RequestMapping("/api/data/query")
@Api(tags = "数据查询")
public class QueryDataController extends Binder{

    private final static Logger log  = LoggerFactory.getLogger(QueryDataController.class);

    @Value("${tms.sign.key}")
    private String signKey ;

    @Resource
    private IQueryDataService queryDataService;

    @ApiOperation(value = "查询剩余学位数接口（实时查)" )
    @RequestMapping(value = "/getSurplusQuota", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<List<ClassQuota>> getSurplusQuota(@RequestBody @Valid QueryClassParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        List<ClassQuota> classQuotaList = queryDataService.findClassQuotaList(requestParam);
        return ResponseResult.success(classQuotaList) ;
    }


    @ApiOperation(value = "查询班级价格接口（实时查）" )
    @RequestMapping(value = "/getZyclassPriceInfo", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<List<ClassFee>> getZyclassPriceInfo(@RequestBody @Valid QueryClassParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        List<ClassFee> classFeeList = queryDataService.findClassFeeList(requestParam);
        return ResponseResult.success(classFeeList) ;
    }

    @ApiOperation(value = "获取学生账户余额（实时查询）" )
    @RequestMapping(value = "/getAccountInfo", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<StudentAccount> getAccountInfo(@RequestBody @Valid QueryAccountParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        StudentAccount studentAccount = queryDataService.findStudentAccount(requestParam);
        return ResponseResult.success(studentAccount) ;
    }

    @ApiOperation(value = "根据ID查询教师的具体信息" )
    @RequestMapping(value = "/queryTeacherInfo", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseResult<List<TmsTeacherDetail>> queryTeacherInfo(@RequestBody @Valid QueryTeacherParam requestParam ){
        Signs.validateKey(requestParam.getKeyString(),requestParam.getTimeNo(),signKey);
        List<TmsTeacherDetail> teacherDetails = queryDataService.findTeacherDetail(requestParam);
        return ResponseResult.success(teacherDetails) ;
    }
}
